package com.ray.client;
import java.io.IOException;
import java.io.InputStream;

import com.ray.basic.BASIC;

public class Client_in  implements Runnable {
	private static boolean status=true;
	private InputStream in;
	private static String clientid=null;
	public Client_in(){
	}
	public Client_in(InputStream in){
		this.in=in;
	}
	public void run(){
		while (status){
			byte [] receiveBuf=new byte[BASIC.get_BUFSIZE()];
			int length=0;
			try {
				length = in.read(receiveBuf,0,BASIC.get_BUFSIZE());
			} catch (IOException e) {
				e.printStackTrace();
				break;
			}
			if (length<0){
				status=false;
				break;
			} 
			String receive= new String(receiveBuf,0,length);
			receive=BASIC.unpack(receive);//unpack package
			System.out.println(receive);
			String[] parts= receive.split("&&");
			if (parts[0].equals("$$ID")){
				clientid=parts[1];
//				System.out.println("Client_in::set clientid");
			}
		}
	}
	public boolean get_status(){
		return status;
	}
	public static String get_clientid(){
		return clientid;
	}
}
